package org.WhyMCA.Utils;

/**
@author Danilo '' Riso >> danilo DOT riso AT gmail DOT com
* @author Androidiani Dev Team
* @version 1.0
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

/*
 * Created by Danilo Riso
 * Il suo scopo e' gestire e normalizzare le stringhe, quando necessario 
 */
public class StringHandler {

	/*
	 *Toglie il + di fronte al numero, per costruire correttamente l'URL per le chiamate
	*/
	public static String consumerKeyHandler(String s) {
		
		// toglie il +
		final String _consumer_key = s;
		
		final String _consumer_key_modified = _consumer_key.substring(1, _consumer_key.length());
		
		return _consumer_key_modified;
		
	}
	
	/*
	 *Manipola array di byte, per codificarli da valori numerici di byte a byte reali
	*/
	public static String createPacketString(byte[] _packetbyte) {
		
		String _connpackstr = "";
		
		for(int _counter = 0; _counter < _packetbyte.length; ++_counter) {
			
			_connpackstr = _connpackstr + StringHandler.convertByteToString(_packetbyte[_counter]);
			
		}
		
		return _connpackstr;
		
	}
	
	/*
	 *Converte i byte in ingresso in stringa
	*/
	public static String convertByteToString(byte args) {
	    
		return new String(new byte[] {args});
	    
	}
		
	/*
	 * Converte le stringhe in ingresso, trasformandole in byte
	*/
	public static byte[] convertStringToByte(String args) {
		if (args== null)
			return null;
		byte[] _packetbyte = null;
		
		try {
			
			_packetbyte = args.getBytes("UTF-8");
			
		} catch (UnsupportedEncodingException e) {
						
			e.printStackTrace();
			
		}
		
		return _packetbyte;
				
	}
		
}
